package com.example.controller;

import com.example.model.MQTTMessage;
import com.example.utils.MQTTUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description : MQTT测试接口
 * @Author : ZYX
 * @Date : 2023/9/19 16:54
 * @Version : 1.0
 **/
@RestController
@RequestMapping("/api/v1/mqttTest")
public class MQTTController {

    @PostMapping("/send")
    public String send(@RequestBody MQTTMessage message) {
        // 发送消息到指定主题
        MQTTUtils.send(message.getTopic(), message.getQos(), message.getContent());
        return "send topic: " + message.getTopic() + ", message : " + message.getContent();
    }

}
